package helpers;

import static org.lwjgl.opengl.GL11.*;

import java.io.Serializable;

public class Circle implements Serializable
{
	private static float toRad(float angle)
	{
		return (float) (Math.PI / 180.0* angle);
	}
	
	public static void draw(int x, int y, int r, int k)
	{
		if (k == 0) return;
		float a = 360.0f / (4.0f * (float) k);
		
		glBegin(GL_LINE_LOOP);
		
		for (float angle = 0.0f; angle < 360.0f; angle += a)
		{
			double A = Math.sin(toRad(angle)) * r;
			double B = Math.cos(toRad(angle)) * r;
			
			glVertex2i((int) (x + B), (int) (y + A));
		}
		
		glEnd();
	}
	
	public static void drawFilled(int x, int y, int r, int k)
	{
		if (k == 0) return;
		float a = 360.0f / (4.0f * (float) k);
		
		glBegin(GL_TRIANGLES);
		
		for (float angle = a; angle < 360.0f + a; angle += a)
		{
			double A1 = Math.sin(toRad(angle)) * r;
			double B1 = Math.cos(toRad(angle)) * r;
			
			double A2 = Math.sin(toRad(angle - a)) * r;
			double B2 = Math.cos(toRad(angle - a)) * r;

			glVertex2d(x + B2, y + A2);
			glVertex2d(x + B1, y + A1);
			glVertex2i(x, y);
		}
		
		glEnd();
	}
}
